package com.hotel.utils;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by LinYaTing on 2018/11/25 21:34
 */
public class WebUtils {

    /**
     * 跳转的通用方法
     * @param request
     * @param response
     * @param uri
     * @throws ServletException
     * @throws IOException
     */
    public static void goTo(HttpServletRequest request, HttpServletResponse response, Object uri)throws ServletException, IOException {
        if (uri instanceof RequestDispatcher) {
            ((RequestDispatcher) uri).forward(request, response);
        }else if (uri instanceof String) {
            response.sendRedirect(request.getContextPath() + uri);
        }
    }

}
